import { useUserStore } from "@/stores/useUserStore";
import { storeToRefs } from "pinia";

export default function () {
  const userStore = useUserStore();
  const { userInfo } = storeToRefs(userStore);

  function handleWriteJournal() {
    if (userInfo.value === null) {
      uni.showModal({
        title: "提示",
        content: "请先登录",
        confirmText: "去登录",
        success: (e) => {
          if (e.confirm) {
            uni.navigateTo({
              url: "/pages/login/login",
            });
          }
        },
      });
    } else {
      uni.navigateTo({
        url: "/pages/journal-create/journal-create",
      });
    }
  }

  return {
    handleWriteJournal,
  };
}
